package com.hamizhong.iflowers.utils;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Random;

import com.hamizhong.iflowers.db.entity.Variety;

public abstract class MyTools {
	/**
	 * 
	 * @param dt
	 * @return yyyy-MM-dd HH:mm:ss
	 */	
	public static final String formatDttm2YYYY_MM_DD_HH_MM_SS(Date dt) {
		String style = "yyyy-MM-dd HH:mm:ss";
		DateFormat df = new SimpleDateFormat(style);
		return df.format(dt);
	}
	
	
	/**
	 * 
	 * @param dt
	 * @return yyyy-MM-dd
	 */	
	public static final String formatDttm2YYYY_MM_DD(Date dt) {
		String style = "yyyy-MM-dd";
		DateFormat df = new SimpleDateFormat(style);
		return df.format(dt);
	}
	
	/**
	 * 
	 * @param dt
	 * @return yyyyMMdd
	 */
	public static final String formatDttm2YYYYMMDD(Date dt) {
		String style = "yyyyMMdd";
		DateFormat df = new SimpleDateFormat(style);
		return df.format(dt);
	}
	
	/**
	 * 
	 * @param dt
	 * @return yyyyMMddHHmmss
	 */
	public static final String formatDttm2YYYYMMDDHHMMSS(Date dt) {
		String style = "yyyyMMddHHmmss";
		DateFormat df = new SimpleDateFormat(style);
		return df.format(dt);
	}
	

	/**
	 * @function 将String转换成给定格式的Date
	 * @param String dtStr
	 * @param String style
	 * @return
	 */
	public static final Date formateString2Date(String dtStr,String style) {
		DateFormat df = new SimpleDateFormat(style);
		Date date = null;
		try {
			date = (Date)df.parse(dtStr);
			return date;
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static final Integer convertItemCnt2PageCnt(Integer itemCnt, Integer pageSize) {
		int pageCnt = 0;
		if(itemCnt%pageSize > 0) {
			pageCnt = itemCnt/pageSize + 1;
		}else {
			pageCnt = itemCnt/pageSize;
		}
		return pageCnt;
	}
	
	public static final String countAVG2OnePoint(Double total,Integer cnt) {
		DecimalFormat df = new DecimalFormat("#.0");
		Double avg = total/cnt;
		return df.format(avg).toString();
	}
	
	public static final String formatFloat1PointStr(Float value) {
		DecimalFormat df = new DecimalFormat();
		String pattern = "#.0";
		df.applyPattern(pattern);
		return df.format(value);
	}
	
	public static final String query10LengthRandomNumStr() {
		Random random = new Random();
		String randomNumStr = random.nextInt(2000000000)+"";
		while (randomNumStr.length() < 10) {
			randomNumStr = "0"+randomNumStr;
		}
		return randomNumStr;
	}
	
}
